package com.zs.service.impl;

import com.zs.service.Action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/6/11 上午10:01
 */
public class LogOutAction implements Action {
    /**
     * @param request
     * @param response
     * @throws Exception
     */
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
        HttpSession session = request.getSession();
        if (session.getAttribute("user") != null) {
            session.removeAttribute("user");
            session.invalidate();
            response.getWriter().print("注销成功");
            return;
        }
        response.getWriter().print("您尚未登录，无需注销");
    }
}
